//
// Description: 5939. 半径为 k 的子数组平均值
// Created by Loading on 2021/11/28.
//

#include <bits/stdc++.h>

using namespace std;

vector<int> getAverages(vector<int> &nums, int k) {
    int n = nums.size();
    vector<int> res(n, -1);
    if (2 * k + 1 <= n) {
        // 前缀和
        long long sum = accumulate(nums.begin(), nums.begin() + 2 * k + 1, 0LL);
        for (int i = k; i < n - k; ++i) {
            if (i != k) {
                sum += nums[i + k] - nums[i - k - 1];
            }
            res[i] = sum / (2 * k + 1);
        }
    }

    return res;
}

int main() {
    vector<int> nums = {7, 4, 3, 9, 1, 8, 5, 2, 6};
    int k = 3;
    vector<int> res = getAverages(nums, k);
    for (auto &x : res) {
        cout << x << ' ';
    }
    cout << endl;

    return 0;
}